package com.cloud.cmt.usermanage.controller;

import com.cloud.cmt.usermanage.dict.entity.Dictionary;
import com.cloud.cmt.usermanage.dict.util.DictData;
import com.google.common.base.Strings;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/dict/")
@Api(value = "/字典接口", description = "查询字典信息-by wcy")
public class DictCtl {

    /**
     * 根节点
     * @param nodeCode
     * @return
     */
    @GetMapping("/findByNodeCode/{nodeCode}")
    @ApiOperation(value = "通过code获取根节点信息")
    public Dictionary findByNodeCode(@PathVariable String nodeCode){
        if (Strings.isNullOrEmpty(nodeCode)){
            return null;
        }
        Dictionary dictionary = DictData.getDicMapByCode(nodeCode);
        return dictionary;
    }

    /**
     * 子节点
     * @param nodeCode
     * @return
     */
    @GetMapping("findByCode/{nodeCode}")
    @ApiOperation(value = "通过code获取子节点信息")
    public List<Dictionary> findByCode(@PathVariable String nodeCode){
        if (Strings.isNullOrEmpty(nodeCode)){
            return new ArrayList<>();
        }

        List<Dictionary> dictionary_list = DictData.getDicListMapByCode(nodeCode);
        return dictionary_list;
    }
}
